package com.tailyou.hms.firstapp.act;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ListView;

import com.tailyou.hms.firstapp.R;
import com.tailyou.hms.firstapp.adapter.CustomAdapter;
import com.tailyou.hms.firstapp.bean.AppBean;

import java.util.ArrayList;

public class BaseAdapterActivity extends AppCompatActivity {

    private CustomAdapter adapter;
    private ArrayList<AppBean> listData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_adapter);
        //findViewById获取列表控件ListView
        ListView listView = findViewById(R.id.list);
        //准备要显示的数据
        getMyList();
        //新建BaseAdapter
        adapter = new CustomAdapter(BaseAdapterActivity.this, listData);
        //给ListView设置Adapter
        listView.setAdapter(adapter);
    }

    /**
     * 准备数据，通常从数据库获取，或者通过后台接口从服务器获取
     */
    private void getMyList() {
        listData = new ArrayList<>();
        listData.add(new AppBean(R.mipmap.ic_alipay,"支付宝","支付宝为大家"));
        listData.add(new AppBean(R.mipmap.ic_google,"谷歌浏览器","想看啥看啥"));
        listData.add(new AppBean(R.mipmap.ic_mitalk,"米聊","聊天面对面"));
    }

}